/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settingslib.spaprivileged.framework.common

import android.app.ActivityManager
import android.app.AlarmManager
import android.app.AppOpsManager
import android.app.admin.DevicePolicyManager
import android.app.usage.StorageStatsManager
import android.apphibernation.AppHibernationManager
import android.content.Context
import android.content.pm.CrossProfileApps
import android.content.pm.verify.domain.DomainVerificationManager
import android.os.UserHandle
import android.os.UserManager
import android.permission.PermissionControllerManager

/** The [ActivityManager] instance. */
val Context.activityManager get() = getSystemService(ActivityManager::class.java)!!

/** The [AlarmManager] instance. */
val Context.alarmManager get() = getSystemService(AlarmManager::class.java)!!

/** The [AppHibernationManager] instance. */
val Context.appHibernationManager get() = getSystemService(AppHibernationManager::class.java)!!

/** The [AppOpsManager] instance. */
val Context.appOpsManager get() = getSystemService(AppOpsManager::class.java)!!

/** The [CrossProfileApps] instance. */
val Context.crossProfileApps get() = getSystemService(CrossProfileApps::class.java)!!

/** The [DevicePolicyManager] instance. */
val Context.devicePolicyManager get() = getSystemService(DevicePolicyManager::class.java)!!

/** The [DomainVerificationManager] instance. */
val Context.domainVerificationManager
    get() = getSystemService(DomainVerificationManager::class.java)!!

/** The [PermissionControllerManager] instance. */
val Context.permissionControllerManager
    get() = getSystemService(PermissionControllerManager::class.java)!!

/** The [StorageStatsManager] instance. */
val Context.storageStatsManager get() = getSystemService(StorageStatsManager::class.java)!!

/** The [UserManager] instance. */
val Context.userManager get() = getSystemService(UserManager::class.java)!!

/** Gets a new [Context] for the given [UserHandle]. */
fun Context.asUser(userHandle: UserHandle): Context = createContextAsUser(userHandle, 0)
